importScripts("js2flowchart.js");

const { createFlowTreeBuilder, ABSTRACTION_LEVELS, convertFlowTreeToSvg } =
  js2flowchart;
self.onmessage = function (message) {
  const code = message.data.code;
  let svg = "",
    shouldUpdate = true;
  try {
    shouldUpdate = true;
    const flowTreeBuilder = createFlowTreeBuilder();
    // flowTreeBuilder.setAbstractionLevel([
    //   ABSTRACTION_LEVELS.FUNCTION_DEPENDENCIES,
    // ]);
    const flowTree = flowTreeBuilder.build(code);
    svg = convertFlowTreeToSvg(flowTree);
  } catch (e) {
    shouldUpdate = false;
    console.log(e);
  } finally {
    shouldUpdate &&
      self.postMessage({
        svg,
      });
  }
};
